﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_ProExtendeProperty.cs
* 创建标识：曾乃强 15158756652 2011-04-01 10:04:13
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_ProExtendeProperty*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_ProExtendeProperty
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_ProExtendeProperty obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "ProExtendeProperty ([ProductID],[StandardVaule],[ProTypeRefExtendPropertyID],[ProductTypeID])");
            sql.Append("values(@ProductID,@StandardVaule,@ProTypeRefExtendPropertyID,@ProductTypeID)");
            sql.Append(";SELECT @@IDENTITY");
            SqlParameter[] pra = {
                            new SqlParameter("@ProductID",obj.ProductID),
							new SqlParameter("@StandardVaule",obj.StandardVaule),
                            new SqlParameter("@ProTypeRefExtendPropertyID",obj.ProTypeRefExtendPropertyID),
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID)
                                 };
            return Convert.ToInt32(DbHelper.ExecuteScalar(sql.ToString(), pra));
        }

        public int Update(Model.CNVP_ProExtendeProperty obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "ProExtendeProperty set [ProductID] = @ProductID,[StandardVaule] = @StandardVaule,[ProTypeRefExtendPropertyID]=@ProTypeRefExtendPropertyID,[ProductTypeID]=@ProductTypeID where [ID]=@ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@ProductID",obj.ProductID),
							new SqlParameter("@StandardVaule",obj.StandardVaule),
                            new SqlParameter("@ProTypeRefExtendPropertyID",obj.ProTypeRefExtendPropertyID),
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_ProExtendeProperty obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "ProExtendeProperty where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }


        public Model.CNVP_ProExtendeProperty LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ProductID],[StandardVaule],[ProTypeRefExtendPropertyID] from " + Prefix + "ProExtendeProperty");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_ProExtendeProperty cnvp_proextendeproperty = new Model.CNVP_ProExtendeProperty();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_proextendeproperty.ProductID = dr["ProductID"] is DBNull ? 0 : (int)dr["ProductID"];
                cnvp_proextendeproperty.StandardVaule = dr["StandardVaule"] is DBNull ? String.Empty : (string)dr["StandardVaule"];
                cnvp_proextendeproperty.ProTypeRefExtendPropertyID = dr["ProTypeRefExtendPropertyID"] is DBNull ? 0 : (int)dr["ProTypeRefExtendPropertyID"];
            }
             return cnvp_proextendeproperty;
        }

        #endregion

        public Model.CNVP_ProExtendeProperty LoadByProTypeRefExtendPropertyIDAndProductID(int ProTypeRefExtendPropertyID, int ProductID)
        {

            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[StandardVaule] from " + Prefix + "ProExtendeProperty");
            sql.Append(" where [ProTypeRefExtendPropertyID] = @ProTypeRefExtendPropertyID and ProductID=@ProductID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProTypeRefExtendPropertyID",ProTypeRefExtendPropertyID),
						 new SqlParameter("@ProductID",ProductID)
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra);
            Model.CNVP_ProExtendeProperty cnvp_proextendeproperty = new Model.CNVP_ProExtendeProperty();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_proextendeproperty.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                cnvp_proextendeproperty.StandardVaule = dr["StandardVaule"] is DBNull ? String.Empty : (string)dr["StandardVaule"];
            }
            return cnvp_proextendeproperty;
        }

        public List<Model.CNVP_ProExtendeProperty> LoadAll(int ProductID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[StandardVaule],[ProTypeRefExtendPropertyID] from " + Prefix + "ProExtendeProperty");
            sql.Append(" where [ProductID] = @ProductID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProductID",ProductID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            List<Model.CNVP_ProExtendeProperty> list = new List<Model.CNVP_ProExtendeProperty>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_ProExtendeProperty cnvp_proextendeproperty = new Model.CNVP_ProExtendeProperty();
                    string xx = dr["ID"].ToString();

                    cnvp_proextendeproperty.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_proextendeproperty.StandardVaule = dr["StandardVaule"] is DBNull ? String.Empty : (string)dr["StandardVaule"];
                    cnvp_proextendeproperty.ProTypeRefExtendPropertyID = dr["ProTypeRefExtendPropertyID"] is DBNull ? 0 : (int)dr["ProTypeRefExtendPropertyID"];
                    list.Add(cnvp_proextendeproperty);
                }
            }
            return list;

        }

        public int DeleteNotIn(int ProductTypeID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "ProExtendeProperty where [ProductTypeID]=" + ProductTypeID + " and [ProTypeRefExtendPropertyID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }

        public int DeleteNotInID(int ProductID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "ProExtendeProperty where [ProductID]=" + ProductID + " and [ID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }
    }
}

